package com.yourenbang.lingyun.transaction.web.service.impl.pay.klks;

import com.yourenbang.lingyun.constants.enums.ChannelIdEnums;
import com.yourenbang.lingyun.constants.enums.pay.PayRateEnum;
import com.yourenbang.lingyun.transaction.constant.LklTransTypeEnum;
import com.yourenbang.lingyun.transaction.web.domain.po.klks.KlksPayTransactionPO;
import com.yourenbang.transaction.api.model.vo.pay.PayTransaction;
import org.apache.commons.lang3.StringUtils;

public class KlksPayConfig {

    /**
     * 卡类型 C:贷记卡
     */
    public static final String CARDFLAG_C = "C";
    /**
     * 卡类型 D:借记卡
     */
    public static final String CARDFLAG_D = "D";
    /**
     * 卡类型 WECHAT:微信
     */
    public static final String CARDFLAG_WECHAT = "WECHAT";
    /**
     * 卡类型 ALIPAY:支付宝
     */
    public static final String CARDFLAG_ALIPAY = "ALIPAY";
    /**
     * 卡类型 82:银联二维码贷记
     */
    public static final String CARDFLAG_82 = "82";

    /**
     * 获取用户订单所在表
     */
    public static int getTransTableIndex(String userBaseId){
        int hashcode = userBaseId.hashCode() % 100;
        return Math.abs(hashcode)+1;
    }

    public static String fmtCrdFlg(String lakalaCrdFlg) {
        switch (lakalaCrdFlg) {
            case "00":
                return CARDFLAG_D;
            case "01":
                return CARDFLAG_C;
            case "91":
                return CARDFLAG_WECHAT;
            case "92":
                return CARDFLAG_ALIPAY;
            default:
                return lakalaCrdFlg;
        }
    }

    public static PayRateEnum fmtRate(String lakalaCrdFlg, Integer rateCredit) {
        switch (lakalaCrdFlg) {
            case "00":
                return PayRateEnum.f50;
            case "01":
                return PayRateEnum.getPayRateByShotCode(rateCredit);
            case "81":
                return PayRateEnum.f50;
            case "82":
                return PayRateEnum.getPayRateByShotCode(rateCredit);
            case "91":
                return PayRateEnum.f38_qr;
            case "92":
                return PayRateEnum.f38_qr;
            default:
                return PayRateEnum.getPayRateByShotCode(rateCredit);
        }
    }

    /**
     * 是否计入分润
     */
    public static Boolean getProfitFlag(PayTransaction payTransaction) {
        if (StringUtils.isBlank(payTransaction.getCardFlag())) {
            return false;
        }

        //押金交易不计入分润
        if (StringUtils.equals(payTransaction.getTransType(), LklTransTypeEnum.TYPE_412001.getTransType())) {
            return false;
        }

        //贷记卡 微信 支付宝 纪录日统计
        if (ChannelIdEnums.isProfitChannel(payTransaction.getChannelId()) &&
                StringUtils.equalsAnyIgnoreCase(payTransaction.getCardFlag(),
                KlksPayTransactionPO.CARDFLAG_C, KlksPayTransactionPO.CARDFLAG_WECHAT,
                KlksPayTransactionPO.CARDFLAG_ALIPAY, KlksPayTransactionPO.CARDFLAG_82)) {
            return true;
        }
        return false;
    }

}
